//
//  HJJRadioRootCell.m
//  Pianke
//
//  Created by 黄俊杰 on 15/12/23.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "HJJRadioRootCell.h"

@implementation HJJRadioRootCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews{
    self.coverimgImageView = [[UIImageView alloc] init];
//    self.coverimgImageView.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.coverimgImageView];
    
    [self.coverimgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(5);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(self.coverimgImageView.mas_left).offset(100);
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
//    self.titleLabel.backgroundColor = [UIColor grayColor];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(-120);
        make.top.mas_equalTo(self.coverimgImageView.mas_top).offset(10);
        make.bottom.mas_equalTo(self.coverimgImageView.mas_top).offset(30);
        make.left.mas_equalTo(self.coverimgImageView.mas_right).offset(10);
    }];
    
    self.countImageView = [[UIImageView alloc] init];
    self.countImageView.image = [UIImage imageNamed:@"umeng_fb_audio_play_default@2x.png"];
    [self.contentView addSubview:self.countImageView];
    
    [self.countImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(-80);
        make.top.mas_equalTo(self.coverimgImageView.mas_top).offset(10);
        make.bottom.mas_equalTo(self.coverimgImageView.mas_top).offset(20);
        make.left.mas_equalTo(self.titleLabel.mas_right).offset(30);
    }];
    
    self.countLable = [[UILabel alloc] init];
//    self.countLable.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.countLable];
    
    [self.countLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(-5);
        make.top.mas_equalTo(self.coverimgImageView.mas_top).offset(7);
        make.bottom.mas_equalTo(self.coverimgImageView.mas_top).offset(25);
        make.left.mas_equalTo(self.countImageView.mas_right).offset(5);
    }];
    
    self.uNameLabel = [[UILabel alloc] init];
//    self.uNameLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.uNameLabel];
    
    [self.uNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(5);
        make.left.mas_equalTo(self.titleLabel);
        make.right.mas_equalTo(self.titleLabel);
        make.bottom.mas_equalTo(self.uNameLabel.mas_top).offset(18);
        
    }];
    
    self.descLabel = [[UILabel alloc] init];
//    self.descLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.descLabel];
    
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.uNameLabel.mas_bottom).offset(10);
        make.bottom.mas_equalTo(self.coverimgImageView).offset(-5);
        make.left.mas_equalTo(self.titleLabel);
        make.right.mas_equalTo(-50);
        
    }];
    
    self.isNewImageView = [[UIImageView alloc] init];
    self.isNewImageView.hidden = YES;
    [self.contentView addSubview:self.isNewImageView];
    
}

-(void)sendModel:(HJJRadioRootModel *)model{

    if (model.isnew) {
        self.isNewImageView.image = [UIImage imageNamed:@"iconfont-tubiao103"];
        self.isNewImageView.hidden = NO;
    }
    
    NSURL *url = [NSURL URLWithString:model.coverimg];
    [self.coverimgImageView sd_setImageWithURL:url placeholderImage:nil];
    self.coverimgImageView.layer.masksToBounds = YES;
    self.coverimgImageView.layer.cornerRadius = 15 * EACH_HEIGHT;
    
    
    self.titleLabel.text = model.title;
    self.titleLabel.textColor = [UIColor colorWithRed:0.16 green:0.24 blue:0.31 alpha:1];
    
    
    self.countLable.text = [NSString stringWithFormat:@"%ld",model.count];
    self.countLable.font = [UIFont systemFontOfSize:10.0 * EACH_HEIGHT];
    
    self.descLabel.text = model.desc;
    self.descLabel.font = [UIFont systemFontOfSize:12.0f];
    self.descLabel.textColor = [UIColor colorWithRed:0.73 green:0.8 blue:0.87 alpha:1];
    
    self.uNameLabel.text = [NSString stringWithFormat:@"by:%@",model.uname];
    self.uNameLabel.font = [UIFont systemFontOfSize:10.0 * EACH_HEIGHT];
    self.uNameLabel.textColor = [UIColor colorWithRed:0.22 green:0.69 blue:0.76 alpha:1];
}


@end
